package com.gs.wzmanager.dao;

import com.gs.wzmanager.dao.mapper.ResourceMapper;
import com.gs.wzmanager.entity.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ResourceDao {

    private Logger logger = LoggerFactory.getLogger(ResourceDao.class);

    @Autowired
    private ResourceMapper mapper;

    //新增资源
    public void addResource(Resource res) {
        try {
            mapper.addResource(res);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    }

    //更新资源
    public void updateResource(Resource res) {
        try {
            mapper.updateResource(res);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    }

    //获取资源列表
    public List<Resource> queryAllResource() {
        try {
            return mapper.queryAllResource();
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    //获取某个资源信息
    public Resource queryResourceById(int id) {
        try {
            return mapper.queryResourceById(id);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    //删除资源
    public void deleteResourceById(int id) {
        try {
            mapper.deleteResourceById(id);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    }


}
